home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3074 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: crl.crl.com!not-for-mail
  2. From: gherlein@crl.com (Greg Herlein)
  3. Newsgroups: comp.lang.c,gnu.gcc.help
  4. Subject: Re: Casting unsigned short as unsigned int -> Bus error
  5. Followup-To: comp.lang.c,gnu.gcc.help
  6. Date: 25 Jan 1996 14:11:41 -0800
  7. Organization: CRL Network Services      (415) 705-6060  [Login: guest]
  8. Message-ID: <4e8v6t$bd2@crl.crl.com>
  9. References: <simmons.820857453@rzdspc1> <820879186snz@genesis.demon.co.uk>
  10. NNTP-Posting-Host: crl.com
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. Lawrence Kirby (fred@genesis.demon.co.uk) wrote:
  14. : In article <simmons.820857453@rzdspc1>
  15. :            simmons@rzdspc1.informatik.uni-hamburg.de "Geoffrey Simmons" writes:
  16.  
  17. : >I have a pointer to a struct with a member declared as unsigned short:
  18. : >
  19. : >        typedef struct {
  20. : >                ...
  21. : >                unsigned short myshort;
  22. : >                ...
  23. : >                } RecType;
  24. : >
  25. : >        RecType *MyRec;
  26. : >
  27. : >Now when I try to dereference that member, casting it to (unsigned int),
  28. : >I get a bus error:
  29. : >
  30. : >        unsigned int myint;
  31. : >
  32. : >        myint = (unsigned int) MyRec->myshort;  /* Bus error! */
  33. : >
  34. : >I'm using GCC 2.7.2 on a SparcStation running SunOS 4.1.4. I've made sure
  35. : >that the pointer points to valid data.
  36.  
  37. : If that is so then the code is perfectly valid (and the cast is redundant) -
  38. : your problem is caused somewhere else. Post a minimal compilable program that
  39. : demonstrates the problem.
  40.  
  41.  
  42. This sounds to me like a problem I had a while back - though I'm not a
  43. Sparc guru enough to know for sure.  I was reading elements from
  44. structures like this too, and got bus errors for not reading on 32 bit
  45. boundaries.  Does it work if you read the myshort variable into a
  46. short *then* cast it to an unsigned int?  I'm not sure what the order
  47. of operations is on the assignment... I would think the dererencing of
  48. the stucture element poinet would be first, but what do I know?  
  49.  
  50. Good luck!
  51.  
  52.  
  53. --
  54. Greg Herlein
  55. gherlein@crl.com
  56. http://www.crl.com/www/users/gh/gherlein (under construction, but there!)
  57. Vallejo, CA
  58.